package org.gd.hellojaxb.adapters;

import javax.xml.bind.annotation.adapters.XmlAdapter;
import java.util.Currency;

/**
 * @author Gorhover
 * @version 1.0
 */
public class CurrencyXmlAdapter extends XmlAdapter<String, Currency> {

    @Override
    public Currency unmarshal(String v) throws Exception {
        if(v == null || v.isEmpty()) {
            return null;
        }
        return java.util.Currency.getInstance(v);
    }

    @Override
    public String marshal(Currency v) throws Exception {
        if(v == null) {
            return null;
        }
        return v.getCurrencyCode();
    }
}
